package jeons.admin.transactions.action;

import java.util.List;

import javax.jws.WebParam.Mode;

import jeons.Basket.dto.BasketDTO;
import jeons.admin.code.biz.CodeBiz;

import jeons.admin.transactions.biz.TransactionsBiz;
import jeons.admin.transactions.dto.BasketSearchDTO;
import jeons.admin.transactions.dto.TransactionDTO;

import org.springbyexample.web.servlet.view.tiles2.TilesUrlBasedViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.org.apache.bcel.internal.classfile.Code;

@Controller
@RequestMapping("admin/transactions")
public class TransactionsAction {
	@Autowired TilesUrlBasedViewResolver tilesUrlBasedViewResolver;
	@Autowired TransactionsBiz transactionsBiz;
	@Autowired CodeBiz codeBiz;
	
	/**
	* @Method Name  : Index
	* @작성일   : 2012. 2. 6.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 :장바구니 ~ 배송완료까지의 모든 정보를 알수있다.
	* @param basketSearchDTO
	* @param model
	* @return
	*/
	@RequestMapping(value="/Allinfo",method=RequestMethod.GET)
	public String Index(@ModelAttribute("search")BasketSearchDTO basketSearchDTO,Model model){
		tilesUrlBasedViewResolver.setTilesDefinitionName("admin");
		model.addAttribute("search", new BasketSearchDTO());
		model.addAttribute("data", transactionsBiz.getList(basketSearchDTO));
		model.addAttribute("code", codeBiz.getCodeSubList("BASKET"));
		return "admin/transactions/Allinfo";
	}
	
	
	
	/**
	* @Method Name  : info_Modify
	* @작성일   : 2012. 2. 6.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 : 운영자가 고객의 배송물품을 정보 업데이트 해준다.
	* @return
	*/
	@RequestMapping(value="/Info_Modify", method=RequestMethod.GET)
	public String info_Modify(Model model,@ModelAttribute("search")BasketSearchDTO basketSearchDTO){
		tilesUrlBasedViewResolver.setTilesDefinitionName("admin");
		model.addAttribute("search", new BasketSearchDTO());
		model.addAttribute("data",transactionsBiz.getTransData(basketSearchDTO));
		model.addAttribute("code", codeBiz.getCodeSubList("BASKET"));
		return "admin/transactions/Info_Modify";
	}
	
	
	/**
	* @Method Name  : info_Transactions
	* @작성일   : 2012. 2. 6.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 : 묶음 ,하나 등등 묶음 안에있는 장바구니 리스트를 보여준다.
	* @param model
	* @param dealno
	* @return
	*/
	@RequestMapping(value="/info_transactions", method=RequestMethod.GET)
		public String info_Transactions(Model model,@RequestParam("dealno")int dealno){
		tilesUrlBasedViewResolver.setTilesDefinitionName("tmpl");
		model.addAttribute("data",transactionsBiz.getSubList(dealno));
		return "admin/transactions/info_transactions";
	}
	
	/**
	* @Method Name  : ModifyAndUpdate
	* @작성일   : 2012. 2. 6.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 : 현재 상태 변경 페이지 (장바구니테이블)
	* @return
	*/
	@RequestMapping(value="/ModifyAndUpdate",method=RequestMethod.GET)
	public String ModifyAndUpdate(Model model){
		tilesUrlBasedViewResolver.setTilesDefinitionName("tmpl");
		model.addAttribute("basket", new BasketDTO());
		model.addAttribute("code", codeBiz.getCodeSubList("BASKET"));
		
		return "admin/transactions/ModifyAndUpdate";
	}
	
	@RequestMapping(value="/ModifyAndUpdate",method=RequestMethod.POST)
	public @ResponseBody String ModifyAndUpdate_OK(@RequestParam("chk")Integer[] chk,@RequestParam("status")Integer status){
		tilesUrlBasedViewResolver.setTilesDefinitionName("tmpl");
		System.out.println("AAAAAAAAAAAAAAAAA");
		transactionsBiz.statusUpdate(chk, status);
		return "하하";
	}
}
